package com.ktwlsoft.fundmanage.controller;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.ktwlsoft.fundmanage.config.InnerCommunicate;
import com.ktwlsoft.fundmanage.payload.fundIn.RegisterThirdPartyUser;
import com.ktwlsoft.fundmanage.payload.innerCommunicate.UserRequest;
import com.ktwlsoft.fundmanage.service.HttpUtils;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(description = "内部交流接口")
@RestController
@RequestMapping("/innerCommunicate")
public class InnerCommunicateController {

    private final InnerCommunicate innerCommunicate;

    public InnerCommunicateController(final InnerCommunicate innerCommunicate) {
        this.innerCommunicate = innerCommunicate;
    }

    @ApiOperation("查询用户")
    @PostMapping("/getUser")
    public ResponseEntity<?> getUser(@RequestBody final UserRequest request) {
        Map<String, String> params = new HashMap<>();
        params.put("certificationId", request.getCertificationId());
        params.put("certificationType", request.getCertificationType());
        params.put("realNam", request.getRealName());
        JSONObject result = HttpUtils.sendGetJson(innerCommunicate.getUserUrl(), null, true, true, params);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("注册用户")
    @PostMapping("/third/register/member")
    public ResponseEntity<?> registerThirdPartyUser(@RequestBody RegisterThirdPartyUser registerThirdPartyUser) {
        JSONObject result = HttpUtils.sendPostJson(innerCommunicate.getRegisterMembeUrl(), registerThirdPartyUser, true,
                true);
        return ResponseEntity.ok(result);
    }

    @ApiOperation("发送短信验证")
    @GetMapping("/third/smsCode")
    public ResponseEntity<?> sendSms(@ApiParam(value = "1-账号存在时需要提示，2-账号不存在时需要提示") final String checkAccount,
            @ApiParam(required = true, value = "手机号") final String mobilePhone) {
        Map<String, String> params = new HashMap<>();
        params.put("checkAccount", checkAccount);
        params.put("mobilePhone", mobilePhone);
        JSONObject result = HttpUtils.sendGetJson(innerCommunicate.getSmsCodeUrl(), null, false, false, params);
        return ResponseEntity.ok(result);
    }
}
